using System;
using System.Collections.Generic;

public class myPlane3D
{
    //Stored as a point p on the plane and a normal vector. Then plane is: (q-p).v = 0. 
    public myPoint3D p0;
    public myVector3D normal;

    //returns a positive number if the point q lies on the side of the plane towards the normal, 0 if q lies on the plane, and a negative number if q lies on the side opposite of the normal.
    public double isinside(myPoint3D q)
    {
        myVector3D v = myVector3D.MakeVector(p0, q);
        return myUtil.computeDotproduct(v, normal);
    }

    public myPlane3D( )
    {
    }

    public Matrix4 GetQuadric()
    {
        Matrix4 Q = new Matrix4();
        double a = this.normal.dX, b = this.normal.dY, c = this.normal.dZ;
        double d = -(this.p0.X * a + this.p0.Y * b + this.p0.Z * c);

        Q.matrix[0, 0] = a * a;
        Q.matrix[0, 1] = a * b;
        Q.matrix[0, 2] = a * c;
        Q.matrix[0, 3] = a * d;

        Q.matrix[1, 0] = Q.matrix[0, 1];
        Q.matrix[1, 1] = b * b;
        Q.matrix[1, 2] = b * c;
        Q.matrix[1, 3] = b * d;

        Q.matrix[2, 0] = Q.matrix[0, 2];
        Q.matrix[2, 1] = Q.matrix[1, 2];
        Q.matrix[2, 2] = c * c;
        Q.matrix[2, 3] = c * d;

        Q.matrix[3, 0] = Q.matrix[0, 3];
        Q.matrix[3, 1] = Q.matrix[1, 3];
        Q.matrix[3, 2] = Q.matrix[2, 3];
        Q.matrix[3, 3] = d * d;

        return Q;
    }
}

